package xyz.scoder;

import java.io.IOException;
import java.io.InputStream;

/**
 * 将输入流全部转换为小写的装饰类
 */
public class LowerCaseInputStream extends InputStream {

    private InputStream inputStream;

    public LowerCaseInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    @Override
    public int read() throws IOException {
        int read = inputStream.read();
        if (read != -1) {
            char c = Character.toLowerCase((char) read);
            return c;
        }
        return -1;
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        int read = inputStream.read(b, off, len);
        for (int i = off; i < off + read; i++) {
            b[i] = (byte) Character.toLowerCase((char)b[i]);
        }
        return read;
    }
}
